package com.xdxc.service.impl;

import com.xdxc.exception.CustomException;
import com.xdxc.model.dto.QuestionForm;
import com.xdxc.service.factory.QuestionTypeStrategyFactory;
import com.xdxc.service.strategy.QuestionTypeStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class QuestionsService {
    @Autowired
    private QuestionTypeStrategyFactory strategyFactory;
    @Transactional
    public boolean addQuestion(QuestionForm questionForm){
        QuestionTypeStrategy strategy = strategyFactory.getStrategy(questionForm.getQuType());

        boolean bo= strategy.handleQuestion(questionForm);
        if (!bo){
            throw  new CustomException(500,"出错了，请联系管理员");
        }
        return true;
    };
}
